import config from '@/config/index.js'

const socket = null;
function socketInit(){
	socket = new WebSocket(config.socketUrl);
	
	socket.onopen = function() {
		console.log('链接成功')
	};
	//   // 接收
	socket.onmessage = function(e ) {
		if(e.data){
			try{		
				this.getMessage(JSON.parse(e.data));
			}catch(e){
				this.getMessage(e.data);
				//TODO handle the exception
			}
		}
	};
	// 连接发生错误
	socket.onerror = function(e) {
		console.log("WebSocket连接发生错误");
	};
	socket.onclose = function(e) {
		console.log("WebSocket关闭");
	};
	
	socket.getMessage = function(e){
		
	}
}



export default socket